package com.zlcx.tz.live.constant;


import com.zlcx.tz.live.exception.BusinessException;

/**
 * <p>redis key</p>
 * <PRE>
 * <BR>    修改记录
 * <BR>-----------------------------------------------
 * <BR>    修改日期         修改人          修改内容
 * </PRE>
 *
 * @author zl
 * @version 1.0
 * @date Created in 2017/11/30 19:30
 * @copyright: Copyright (c) founders
 */

public class RedisKeyConst {

    public static final String APPLICATION_PRE = "tz-live-video";

    /**
     * redis中间前缀
     */
    public static final String REDIS_SPLIT_PRE = ":";

    /**
     * redis中间后缀
     */
    public static final String REDIS_SPLIT_SUFFIX = "_";

    /**
     * 获取redis的key
     *
     * @param pre
     * @param argArray
     * @return
     */
    private static String getKeyArray(String pre, Object[] argArray) {
        if (argArray != null && argArray.length != 0) {
            StringBuffer sb = new StringBuffer();
            sb.append(APPLICATION_PRE).append(REDIS_SPLIT_PRE).append(pre);
            int start = 0;
            for (int i = 0; i < argArray.length; i++) {
                if (argArray[i] == null) {
                    continue;
                }
                if (start == 0) {
                    sb.append(REDIS_SPLIT_PRE);
                } else {
                    sb.append(REDIS_SPLIT_SUFFIX);
                }
                sb.append(argArray[i]);
                start++;
            }
            return sb.toString();
        } else {
            throw new BusinessException("key empty or null argument array");
        }
    }

    /**
     * 锁前缀
     * @param lockKey
     * @return
     */
    private static String getLockKey(String lockKey) {
        return getKeyArray("Lock", new String[]{lockKey});
    }

    /**
     *  开关前缀
     * @return
     */
    private static String getSwitchKey(String switchKey) {
        return getKeyArray("Switch", new String[]{switchKey});
    }


    /**
     * 系统配置
     * @param confKey
     * @return
     */
    private static String getSysConfKey(String confKey) {
        return getKeyArray("SysConf", new String[]{confKey});
    }

    private static final String roomInfoById = "room:info:id";
    public static String getRoomInfoByIdKey(String obj) {
        return getKeyArray(roomInfoById, new String[]{obj});
    }

    public static String getRoomInfoClosedByIdKey(Long roomId) {
        return getKeyArray("room:closed:info:id", new String[]{roomId.toString()});
    }

    /**
     * 房间连麦人数
     */
    private static final String roomPublisherCount = "room:publisher:count";
    public static String getRoomPublisherCountKey(String roomId) {
        return getKeyArray(roomPublisherCount, new String[]{roomId});
    }

    /**
     * 房间观众人数
     */
    private static final String roomAudienceCount = "room:audience:count";
    public static String getRoomAudienceCountKey(String obj) {
        return getKeyArray(roomAudienceCount, new String[]{obj});
    }

    /**
     * 房间列表
     */
//    private static final String roomList = "room:list";
//    public static String getRoomListKey() {
//        return getKeyArray(roomList, new String[]{"roomList"});
//    }

//    public static String getRoomListCountKey() {
//        return getKeyArray(roomList, new String[]{"roomListCount"});
//    }

    /**
     * 开始学习时间
     * @param userId
     * @return
     */
    public static String getStartLearnTaskKey(Long userId,Long roomId) {
        return getKeyArray("StartLearnTask", new String[]{userId.toString(),roomId.toString()});
    }

    public static String getStopLearnTaskKey(Long userId,Long roomId) {
        return getKeyArray("StopLearnTask", new String[]{userId.toString(),roomId.toString()});
    }

    /**
     * 当前学习时长
     * @param userId
     * @param roomId
     * @return
     */
    public static String getStudySecondsKey(Long userId,Long roomId) {
        return getKeyArray("StudySeconds", new String[]{userId.toString(),roomId.toString()});
    }

//    public static String getUserJoinRecordMapKey(Long roomId) {
//        return getKeyArray("room:usersList", new String[]{roomId.toString()});
//    }

    /**
     * 连麦心跳
     * @param userId
     * @return
     */
    public static String getLiveTaskKey(Long userId,Long roomId) {
        return getKeyArray("LiveTask", new String[]{userId.toString(),roomId.toString()});
    }

    public static String getLostLiveCountKey(Long userId,Long roomId) {
        return getKeyArray("LostLiveCount", new String[]{userId.toString(),roomId.toString()});
    }

    /**
     * 检查心跳锁
     * @return
     */
    public static String getCheckLiveTaskLockKey() {
        return getLockKey("CheckLiveTaskLock");
    }

    public static String getAlertAcountMounthUsageLockKey() {
        return getLockKey("AlertAcountMounthUsageLock");
    }

    public static String getAutoCloseRoomLockKey() {
        return getLockKey("autoCloseRoomLockKey");
    }
    public static String getBackupCloseRoomLockKey() {
        return getLockKey("backupCloseRoomLockKey");
    }

    public static String getCheckTimeLearnRoomLockKey() {
        return getLockKey("checkTimeLearnRoomLockKey");
    }

    public static String getKickingTimeLearnRoomLockKey() {
        return getLockKey("kickingTimeLearnRoomLockKey");
    }

    /**
     * 当前直播状态
     * @param userId
     * @param roomId
     * @return
     */
    public static String getCurrentPublishingRecordKey(Long userId,Long roomId) {
        return getKeyArray("CurrentPublishingRecord", new String[]{userId.toString(),roomId.toString()});
    }


    /**
     * 监控开关
     * @return
     */
    public static String getFilterSwitchKey() {
        return  getSwitchKey("FilterSwitch");
    }


    public static String getAdminCloseRoomSignKey(Long roomId) {
        return getKeyArray("AdminCloseRoomSign", new String[]{roomId.toString()});
    }

    public static String getAdminKickingUserSignKey(Long userId) {
        return getKeyArray("AdminKickingUserSign", new String[]{userId.toString()});
    }

    public static String getPickCheckAlertTimeKey(Long roomId,Long userId) {
        return getKeyArray("PickCheckAlertTime", new String[]{roomId.toString(),userId.toString()});
    }

    /**
     * 提交锁
     * @return
     */
    public static String getSubmitLockKey(String lockKey) {
        return getLockKey("SubmitLock:"+lockKey);
    }

    /**
     * 声网当前账号
     * @return
     */
    public static String getCurrentAgoraAcountKey() {
        return getKeyArray("AgoraAcount", new String[]{"Current"});
    }

    public static String getUserInfoKey(Long userId) {
        return getKeyArray("UserInfo", new String[]{userId.toString()});
    }

    /**
     * 已经取消的申请id集合
     * @param roomId
     * @return
     */
    public static String getCancelPublishingRecordSetKey(Long roomId) {
        return getKeyArray("CancelPublishingRecordSet", new String[]{roomId.toString()});
    }

    /**
     * 录制图片地址
     * @param userId
     * @param roomId
     * @return
     */
    public static String getRecordingPicDirKey(Long userId,Long roomId) {
        return getKeyArray("RecordingPicDir", new String[]{userId.toString(),roomId.toString()});
    }

    /**
     * 正在合成图片标记
     * @param userId
     * @param roomId
     * @return
     */
    public static String getCreateVideoStatusKey(Long userId,Long roomId) {
        return getKeyArray("CreateVideoStatus", new String[]{userId.toString(),roomId.toString()});
    }

    /**
     *  用户当前视频地址
     * @param userId
     * @param roomId
     * @return
     */
    public static String getUserVideoUrlKey(Long userId,Long roomId) {
        return getKeyArray("UserVideoUrl", new String[]{userId.toString(),roomId.toString()});
    }

    public static String getSocketSwitchKey() {
        return  getSwitchKey("SocketSwitch");
    }


    public static String getSysConfComplainMailsKey() {
        return getSysConfKey("ComplainMails");
    }

    public static String getSysConfComplainPhonesKey() {
        return getSysConfKey("ComplainPhones");
    }

    public static String getRoomCloseDelayStatusKey(Long roomId) {
        return getKeyArray("RoomCloseDelayStatus", new String[]{roomId.toString()});
    }



}
